package com.mobile2you.nci.android.utils;

import java.io.File;

import android.content.Context;

public class FileCache {

	private File cacheDir;

	/**
	 * Find the dir to save cached images
	 * 
	 * @param context
	 *            :Current activity context
	 */
	public FileCache(Context context) {
		if (android.os.Environment.getExternalStorageState().equals(
				android.os.Environment.MEDIA_MOUNTED)) {
			cacheDir = new File(
					android.os.Environment.getExternalStorageDirectory(),
					ImageUtils.NAME);
		} else {
			cacheDir = context.getCacheDir();
		}
		if (!cacheDir.exists()) {
			cacheDir.mkdirs();
		}
	}

	public void clear() {
		File[] files = cacheDir.listFiles();
		for (File f : files) {
			f.delete();
		}
	}

	public void deleteFolder() {
		cacheDir.delete();
	}

	public File getFile(String url) {
		String filename = String.valueOf(url.hashCode());
		File f = new File(cacheDir, filename);
		return f;

	}

}
